<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Syntax_haighlightHelper
 *
 * @author Thiago
 */
class SyntaxHelper extends AppHelper{
  public $helpers = array('Html');
  
  /**
   * @example Exibe o código fonte dos arquivos na pasta webroot/files/exemplos_fontes
   * @param string $filename
   * @return codigo fonte
   */
  function highlight($filename) { 
    
    $filename = 'files/exemplos_fontes/' . $filename;
    if(file_exists($filename) && is_file($filename)) { 

      $output = '<div class="php_highlight"><pre><code>'; 
      
      ini_set('highlight.comment', '"class="highlight_comment');
      ini_set('highlight.default', '"class="highlight_default');
      ini_set('highlight.keyword','"class="highlight_keyword');
      ini_set('highlight.string', '"class="highlight_string');

      $code = substr(highlight_file($filename, true), 36, -15); 
        
      $start_line = 1; 
      $lines = explode('<br />', $code); 
      
      $chr_lines = count($lines); 
      $chr_lines = strlen($chr_lines); 

      foreach($lines as $line) {    
        $nline = str_pad($start_line, $chr_lines, ' ', STR_PAD_LEFT);
        $output .= '<span class="php_highlight_line">'.$nline. ':</span>' .$line ."<br>"; 
        $start_line ++; 
      } 
        $output .= '</code></pre></div>'; 
        return $output;
    } 
  } 


  
}

?>